<template id="MonitorDialog">
  <div class="MonitorDialog">
    <div class="head">
      <div class="windowIcon"></div>
      <p class="title">{{ monitorData.name }}</p>
      <div class="closeButton" @click="closeMonitorDialog"></div>
    </div>
    <div class="main">
      <div v-if="monitorData.sys_id == 38">
        <iframe
          ref="iframe"
          @load="loaded"
          frameborder="no"
          :src="`http://172.16.11.112:8088/ws.html?autoplay=true&token=${monitorData['index_code']}`"
        ></iframe>
      </div>
      <div v-else-if="monitorData.sys_id == 29">
        <div class="VR">
          <p>查看AR监控请下载安装VideoWebPlugin控件后再点击查看监控按钮</p>
          <el-link type="primary" :underline="false" @click="downAR"
            >下载VideoWebPlugin</el-link
          >
        </div>
      </div>
      <div v-else>
        <LivePlayerDemo
          :autoplay="true"
          :videourl="monitorData['preview_url']"
          @errorUrl="errorUrl"
        />
      </div>
    </div>
    <div
      class="foot"
      v-if="monitorData.sys_id !== 38"
      @click="checkMonitorDialog"
    >
      点击查看监控
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
import LivePlayerDemo from "components/LivePlayerDemo.vue";
export default {
  name: "MonitorDialog",
  components: {
    LivePlayerDemo,
  },
  props: {
    monitorData: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  // 定义属性
  data() {
    return {
      wins: {},
      timers: null,
      cameraIndexCodes: [],
    };
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    //  视频链接播放错误
    errorUrl(n) {
      this.$emit("errorUrl", n);
    },
    closeMonitorDialog() {
      this.$emit("closeMonitorDialog");
    },
    checkMonitorDialog() {
      //   this.$emit("checkMonitor");
      const { index_code } = this.monitorData;
      this.flag = this.checkCode(index_code);
      if (this.flag == false) return;
      this.cameraIndexCodes.push(index_code);
      //console.log(this.cameraIndexCodes, "this.cameraIndexCodes");
      this.g_OpenWindow(
        "./play.html?" + this.cameraIndexCodes.join(";"),
        860,
        600
      );
    },
    checkCode(code) {
      let flag = true;
      $.each(this.cameraIndexCodes, function (i, n) {
        if (code == n) {
          flag = false;
          return flag;
        }
      });
      return flag;
    },
    // 打开窗口
    g_OpenWindow(pageURL, innerWidth, innerHeight) {
      let ScreenWidth = window.screen.availWidth;
      let ScreenHeight = window.screen.availHeight;
      let StartX = (ScreenWidth - innerWidth) / 2;
      let StartY = (ScreenHeight - innerHeight) / 2;
      this.wins = window.open(
        pageURL,
        "OpenWin",
        "left=" +
          StartX +
          ", top=" +
          StartY +
          ", Width=" +
          innerWidth +
          ", height=" +
          innerHeight +
          ", resizable=no, scrollbars=yes, status=no, toolbar=no, menubar=no, location=no"
      );

      this.timers = setInterval(() => {
        this.isCloseWin();
      }, 500);
      this.wins.focus();
      this.wins.onbeforeunload = function () {
        this.cameraIndexCodes = [];
      };
    },
    isCloseWin() {
      if (this.wins.closed) {
        this.cameraIndexCodes = [];
        this.timers && clearInterval(this.timers);
      }
    },
    loaded() {},
    downAR() {
      // window.location.href = "http://172.16.11.111:82/VideoWebPlugin.exe";
       window.location.href = "http://tbknew.mpcheshi.com/VideoWebPlugin.exe";
    },
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    //console.log(this.monitorData);
    //console.log(this.monitorData["preview_url"]);
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>

<style lang="scss" scoped>
.MonitorDialog {
  background-image: linear-gradient(
    90deg,
    rgba(3, 83, 165, 0.72) 0%,
    rgba(3, 56, 117, 0.93) 61%,
    rgba(3, 53, 110, 0.96) 100%
  );
  box-shadow: 0vw 0.13vw 0.52vw 0vw rgba(0, 0, 0, 0.26);
  border-radius: 0.21vw;
  border: solid 0.05vw #34a1ff;
  .head {
    display: flex;
    align-items: center;
    padding: 0.58vw 1.3vw;
    border-bottom: 0.03vw solid #03d0fd;
    .windowIcon {
      background: url("../../../../../../../assets/images/indexBody/amapDialog/windowIcon.png");
      background-size: 100% 100%;
      width: 0.73vw;
      height: 0.6vw;
    }
    .title {
      font-size: 0.63vw;
      color: #03f2fb;
      margin: 0 auto 0 0.44vw;
      user-select: none;
    }
    .closeButton {
      background: url("../../../../../../../assets/images/indexBody/amapDialog/closeButton.png");
      background-size: 100% 100%;
      width: 0.52vw;
      height: 0.52vw;
      cursor: pointer;
    }
  }
  .main {
    iframe {
      width: 100%;
      // height: 21.3vw;
      height: 15.7vw;
    }
    .VR {
      padding: 0.58vw 1.3vw 0 1.3vw;
      p {
        color: #fff;
        line-height: 1vw;
        user-select: none;
      }
      .el-link {
        margin-top: 0.5vw;
        color: #03f2fb;
      }
      .el-link:hover {
        text-decoration: underline;
      }
    }
  }
  .foot {
    background: url("../../../../../../../assets/images/indexBody/amapDialog/buttonStyle.png");
    background-size: 100% 100%;
    width: 3.8vw;
    height: 1vw;
    font-size: 0.52vw;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    cursor: pointer;
    margin: 0.6vw auto;
    user-select: none;
  }
  .foot:hover {
    color: #03f2fb;
  }
}
</style>
